﻿using System;
using System.Collections.Generic;
using Orid.Management.Statistics.Tools.Decomposition.Model;
using Orid.Management.Common.Job;


namespace Orid.Management.Statistics.Tools.Decomposition.Data
{
    class ChildDatdaOnline : ChildData
    {
        private string connectString, ChildDatasTableName;
        private DataStore dataSotre  ;

        public ChildDatdaOnline(string dataDBAddress)
        {
            connectString = dataDBAddress;
            ChildDatasTableName = "  [FutureManagement_Stores].[FutureMa].[ChildDatas]";
            dataSotre = new DataStoreOnline(dataDBAddress);
        }

        Account account = new  AccountOnline();

        public override ModelFrameObject GetFrameData(Guid ChildDataID)
        {
            try
            {
                if (ChildDataID == null)
                {
                    return null;
                }
                ModelFrameObject model =  GetFrameData(ChildDataID, connectString, ChildDatasTableName);

                if ((model!=null) && (model.DataStoreID != null))
                {
                    model.FileSize = dataSotre.GetFileSize(model.DataStoreID);
                }
                return model;

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public override ModelBlockObject GetBlockData(Guid ChildDataID)
        {

            try
            {
                if (ChildDataID == null)
                {
                    return null;
                }

                ModelBlockObject model =  GetBlockData(ChildDataID, connectString, ChildDatasTableName);

                if ((model!=null) &&(model.DataStoreID != null))
                {
                    model.FileSize = dataSotre.GetFileSize(model.DataStoreID);
                }
                return model;

            }
            catch (Exception ex)
            {
                throw ex;
            }




        }

        public override ModelJudgeObject GetJudgeData(Guid ChildDataID)
        {
            try
            {

                if (ChildDataID == null)
                {
                    return null;
                }

                ModelJudgeObject model =  GetJudgeData(ChildDataID, connectString, ChildDatasTableName,new AccountOnline());

                if ((model!=null) &&(model.DataStoreID != null))
                {
                    model.FileSize = dataSotre.GetFileSize(model.DataStoreID);
                }
                return model;
            }
            catch (Exception ex)
            {
                throw ex;
            }




        }

        public override ModelInputObject GetInputObject(Guid ChildDataID)
        {
            try
            {
                if (ChildDataID == null)
                {
                    return null;
                }

                ModelInputObject model = GetInputObject(ChildDataID, connectString, ChildDatasTableName, new AccountOnline());
                if ((model!=null) &&(model.DataStoreID != null))
                {
                    model.FileSize = dataSotre.GetFileSize(model.DataStoreID);
                }
                return model;

            }
            catch (Exception ex)
            {
                throw ex;
            }




        }

        public override List<ModelOrderRecord> GetChildID(Guid orderID)
        {
            try
            {
                if (orderID == null)
                {
                    return null;
                }

                return GetChildID(orderID, connectString, ChildDatasTableName);

            }
            catch (Exception ex)
            {
                throw ex;
            }


        }

        public override Guid GetParentID(Guid ChildDataID)
        {

            try
            {
                return GetParentID(ChildDataID, connectString, ChildDatasTableName);
            }
            catch (Exception ex)
            {
                throw ex;
            }


        }

        public override  BlockImage GetBlockImage(Guid FrameID, int Left, int Top, int Width, int Height)
        {
            try
            {
                return GetBlockImage(FrameID, Left, Top, Width, Height, connectString, ChildDatasTableName);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public override List<ModelFrameResult> GetFrameResult(Guid ChildDataID)
        {
            try
            {
                if (ChildDataID == null)
                {
                    return null;
                }


                List<ModelFrameResult> modelList = GetFrameResult(ChildDataID, connectString, ChildDatasTableName);

                if (modelList != null) 
                {
                    foreach (ModelFrameResult item in modelList)
	                {
                		 item.FileSize = dataSotre.GetFileSize(item.DataStoreID);
	                }
                    
                }
                return modelList;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
    }
}
